package com.liao.starapp;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;

import com.liao.starapp.star.StarDiagramViewPagerAdapter;

import java.util.ArrayList;

public class GuideActivity extends AppCompatActivity implements View.OnClickListener {
    private ViewPager viewPager;
    private int[] imgs = new int[]{R.mipmap.loading1, R.mipmap.loading2, R.mipmap.loading3};
    private Button btn_into;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        viewPager = findViewById(R.id.viewPager_guide);
        btn_into = findViewById(R.id.btn_into);
        btn_into.setOnClickListener(this);
        ArrayList<View> views = new ArrayList<>();
        for (int img : imgs) {
            ImageView imageView = new ImageView(this);
            imageView.setImageResource(img);
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            views.add(imageView);
        }
        StarDiagramViewPagerAdapter adapter = new StarDiagramViewPagerAdapter(views);
        viewPager.setAdapter(adapter);
        viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                if (position == imgs.length - 1) {
                    btn_into.setVisibility(View.VISIBLE);
                } else {
                    btn_into.setVisibility(View.GONE);
                }
            }
        });
    }

    @Override
    public void onClick(View v) {
        startActivity(new Intent(this, MainActivity.class));
        finish();
    }
}
